import { Injectable } from '@angular/core';
import { Http }    from '@angular/http';
import 'rxjs/add/operator/toPromise';

export class Factory {
  constructor(argument) {
    // code...
  }
}

@Injectable()
export class  OrderService {
  constructor(private http:Http) { 
  }
  public getAll() {
    return this.http.get(`/api/order/`)
      .toPromise()
      .then(response => {
        return response.json()
     })
   }
  public getByUserId(id) {
    return this.http.get(`/api/order/user/${id}`)
      .toPromise()
      .then(response => {
        return response.json()
      })
  }
  public recipientOrder(param) {
    return this.http.post(`/api/order/recipient`, param)
      .toPromise()
      .then(response => {
        return response.json()
      })
  }
  public updateOrderStatus(param) {
    return this.http.post(`/api/order/status`, param)
      .toPromise()
      .then(response => {
        return response.json()
      })
  }
  public getByRecipientId(id) {
    return this.http.get(`/api/order/recipient/${id}`)
      .toPromise()
      .then(response => {
        return response.json()
      })
  }
  public save(order){
    return this.http.post('/api/order/', order)
      .toPromise()
      .then(response => {
        return response.json()
      })
  }

  public commentOrder(param) {
    return this.http.post('/api/order/comments', param)
      .toPromise()
      .then(response => {
        return response.json()
      })
  }
  public loadCommemt(id) {
    return this.http.get(`/api/order/comments/${id}`)
      .toPromise()
      .then(response => {
        return response.json()
      })
  }
} 